package cn.edu.hbpu.controller.v1;

import cn.edu.hbpu.common.R;
import cn.edu.hbpu.entity.SecondCategory;
import cn.edu.hbpu.service.SecondCategoryService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * @author lcy
 * @date 2022/8/16 18:25
 * @description
 */
@Slf4j
@RestController
@RequestMapping("/secondCategory")
public class SecondCategoryController {

    @Autowired
    private SecondCategoryService secondCategoryService;


    /**
     * 删除二级分类
     *
     * @param sId
     * @return
     */
    @DeleteMapping("/{sId}")
    public R<String> deleteSecondCategory(@PathVariable("sId") String sId) {
        return secondCategoryService.deleteSecondCategory(sId);
    }

    /**
     * 分页查询二级分类。实现了搜索功能
     * @param searchField
     * @param searchText
     * @param startDateTime
     * @param endDateTime
     * @param page
     * @param pageSize
     * @return
     */
    @GetMapping("/pagingQuery")
    public R<Page<SecondCategory>> pagingQuery(String searchField, String searchText, String startDateTime, String endDateTime, @NotNull int page, @NotNull int pageSize) {
        return secondCategoryService.pagingQuery(searchField, searchText, startDateTime, endDateTime, page, pageSize);
    }
}
